<?php
namespace app\home\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\home\model\LoginModel;

class Login extends Controller
{
	/**
	*	登录
	*/
	public function login()
	{
		return $this->fetch();
	}

	/**
	*	验证登录信息
	*/
	public function postDologin()
	{
		$data = $this->request->param();
		$LoginModel = new LoginModel();
		$list = $LoginModel->postDologin($data);
		if($list === 1){

			return returnJson($code=0,$msg='登录成功',$list);

		}elseif($list['error'] === 2){

			return returnJson($code=1,$msg='该手机号码已注册',$list);

		}elseif($list['error'] === 3){

			return returnJson($code=2,$msg='手机号码与发短信的号码不一致',$list);

		}elseif($list['error'] === 4){

			return returnJson($code=3,$msg='验证码错误',$list);

		}elseif($list === 5){
			
			return returnJson($code=4,$msg='该手机号码未注册',$list);
		}
	}

	/**
	*	获取验证码
	*/
	public function getCode()
	{
		/* 获取手机号码 */
		$data = $this->request->param();
		$LoginModel = new LoginModel();
		$list = $LoginModel->getCode($data['phone']);
		if($list){
			return returnJson($code=0,$msg="获取成功",$list);
		}else{
			return returnJson($code=1,$msg="获取失败",$list);
		}
	}

	/**
	*	输入推荐id
	*/
	public function recommend()
	{
		$data = $this->request->param();
		$this->assign('u_tel',isset($data['u_tel']) ? $data['u_tel'] : '');
		return $this->fetch();
	}

	/**
	*	会员注册
	*/
	public function register()
	{
		$data = $this->request->param();
		$LoginModel = new LoginModel();
		$list = $LoginModel->addHomeUser($data);
		if($list){
			return returnJson($code=0,$msg="注册成功",$list);
		}else{
			return returnJson($code=1,$msg="注册失败",$list);
		}
	}

	/**
	*	注销会员
	*/
	public function loginOut()
	{
		Session::clear();
		return true;
	}
}